{% extends '@SyliusAdmin/layout.html.twig' %}

{% import '@SyliusUi/Macro/buttons.html.twig' as buttons %}

{% block title %}{{ 'sylius_refund.ui.credit_memo'|trans ~ ' ' ~ credit_memo.number }} {{ parent() }}{% endblock %}

{% block content %}
    <div class="ui stackable two column grid">
        <div class="eight wide column">
            {% include '@SyliusRefundPlugin/Order/Admin/CreditMemo/_header.html.twig' %}
            {% include '@SyliusRefundPlugin/Order/Admin/CreditMemo/_breadcrumb.html.twig' %}
        </div>
        <div class="eight wide right aligned column">
            {{ buttons.default(
                path('sylius_refund_admin_credit_memo_download', {'id': credit_memo.id}),
                'sylius_refund.ui.download',
                null,
                'download',
                'blue'
            ) }}
        </div>
    </div>
    {% if credit_memo.from != null or credit_memo.to != null %}
    <div class="ui stackable grid">
        {% if credit_memo.from != null %}
        <div class="eight wide column">
            <h4 class="ui top attached styled header">{{ 'sylius_refund.ui.buyer'|trans }}</h4>
            <div class="ui attached segment" id="from-address">
                {% set from = credit_memo.from %}
                <address>
                    <strong>{{ from.fullName }}</strong>
                    {% if from.company %}
                        {{ from.company }}
                    {% endif %}
                    <br/>{{ from.street }}<br/>
                    {{ from.city }}<br/>
                    {% if from.provinceName is not empty %}
                        {{ from.provinceName }}<br/>
                    {% endif %}
                    <i class="{{ from.countryCode|lower }} flag"></i>
                    {{ from.countryCode|sylius_country_name|upper }} {{ from.postcode }}
                </address>
            </div>
        </div>
        {% endif %}
        {% if credit_memo.to != null and credit_memo.to.taxId != null %}
        <div class="eight wide column">
            <h4 class="ui top attached styled header">{{ 'sylius_refund.ui.seller'|trans }}</h4>
            <div class="ui attached segment" id="to-address">
                {% set to = credit_memo.to %}
                <address>
                    <strong>{{ to.company }}</strong>
                    {{ to.taxId }}<br/>
                    {{ to.city }}<br/>
                    {{ to.street }}<br/>
                    <i class="{{ to.countryCode|lower }} flag"></i>
                    {{ to.countryCode|sylius_country_name|upper }} {{ to.postcode }}
                </address>
            </div>
        </div>
        {% endif %}
    </div>
    {% endif %}
    <div class="ui stackable segment grid">
        <div class="sixteen wide column">
            <table class="ui celled compact small table fixed">
                <thead>
                <tr>
                    <th class="four wide">{{ 'sylius_refund.ui.no'|trans }}</th>
                    <th class="four wide sylius-table-column-name">{{ 'sylius.ui.name'|trans }}</th>
                    <th class="four wide sylius-table-column-quantity">{{ 'sylius.ui.quantity'|trans }}</th>
                    <th class="four wide">{{ 'sylius_refund.ui.unit_net_price'|trans }}</th>
                    <th class="four wide sylius-table-column-net_value">{{ 'sylius_refund.ui.net_value'|trans }}</th>
                    <th class="four wide">{{ 'sylius_refund.ui.tax_rate'|trans }}</th>
                    <th class="four wide sylius-table-column-tax_amount">{{ 'sylius_refund.ui.tax_amount'|trans }}</th>
                    <th class="four wide sylius-table-column-gross_value">{{ 'sylius_refund.ui.gross_value'|trans }}</th>
                    <th class="four wide sylius-table-column-currency_code">{{ 'sylius.ui.currency'|trans }}</th>
                </tr>
                </thead>
                <tbody>
                {% for item in credit_memo.lineItems %}
                    <tr>
                        <td class="single line">
                            {{ loop.index }}
                        </td>
                        <td class="single line line-item-name">
                            {{ item.name }}
                        </td>
                        <td class="single line line-item-quantity">
                            {{ item.quantity }}
                        </td>
                        <td class="right aligned line-item-unit-net-price">
                            {{ '%0.2f'|format(item.unitNetPrice/100) }}
                        </td>
                        <td class="right aligned line-item-net-value">
                            {{ '%0.2f'|format(item.netValue/100) }}
                        </td>
                        <td class="single line">
                            {{ item.taxRate }}
                        </td>
                        <td class="right aligned line-item-tax-amount">
                            {{ '%0.2f'|format(item.taxAmount/100) }}
                        </td>
                        <td class="right aligned line-item-gross-value">
                            {{ '%0.2f'|format(item.grossValue/100) }}
                        </td>
                        <td class="single line line-item-currency-code">
                            {{ credit_memo.currencyCode }}
                        </td>
                    </tr>
                {% endfor %}
                </tbody>
                <tfoot>
                    <tr>
                        <th colspan="7" class="right aligned">
                            <strong>{{ 'sylius.ui.total'|trans }}</strong>:
                        </th>
                        <th id="credit-memo-total" class="right aligned">
                            {{ '%0.2f'|format(credit_memo.total/100) }}
                        </th>
                        <th id="credit-memo-total-currency-code" class="single line">
                            {{ credit_memo.currencyCode }}
                        </th>
                    </tr>
                    {% for item in credit_memo.taxItems %}
                        <tr class="tax-item">
                            <th colspan="7" class="right aligned">
                                {{ item.label }}:
                            </th>
                            <th class="right aligned tax-item-amount">
                                {{ '%0.2f'|format(item.amount/100) }}
                            </th>
                            <th class="single line tax-item-currency-code">
                                {{ credit_memo.currencyCode }}
                            </th>
                        </tr>
                    {% endfor %}
                </tfoot>
            </table>

            {% if credit_memo.comment != '' %}
            <div class="ui sizer vertical segment">
                <div class="ui tiny header">{{ 'sylius.ui.comment'|trans }}</div>
                <p id="credit-memo-comment">{{ credit_memo.comment }}</p>
            </div>
            {% endif %}
        </div>
    </div>
{% endblock %}
